package com.hongxun.modules.csg.service.impl;

import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.hongxun.modules.csg.dao.CScheduleDao;
import com.hongxun.modules.csg.entity.CScheduleEntity;
import com.hongxun.modules.csg.service.CScheduleService;



@Service("cScheduleService")
public class CScheduleServiceImpl implements CScheduleService {
	@Autowired
	private CScheduleDao cScheduleDao;
	
	@Override
	public CScheduleEntity queryObject(String guid){
		return cScheduleDao.queryObject(guid);
	}
	
	@Override
	public List<CScheduleEntity> queryList(Map<String, Object> map){
		return cScheduleDao.queryList(map);
	}

	@Override
	public List<CScheduleEntity> queryListForInverTime(Map<String, Object> map){
		return cScheduleDao.queryListForInverTime(map);
	}

	@Override
	public int queryTotal(Map<String, Object> map){
		return cScheduleDao.queryTotal(map);
	}
	
	@Override
	public void save(CScheduleEntity cSchedule){
        if(cSchedule.getGuid()==null||cSchedule.getGuid().equals("")) {

		    cSchedule.setGuid(UUID.randomUUID().toString());
        }
		cScheduleDao.save(cSchedule);
	}
	
	@Override
	public void update(CScheduleEntity cSchedule){
		cScheduleDao.update(cSchedule);
	}
	
	@Override
	public void delete(String guid){
		cScheduleDao.delete(guid);
	}
	
	@Override
	public void deleteBatch(String[] guids){
		cScheduleDao.deleteBatch(guids);
	}

	@Override
	public void insertOrReplaceOrDelete(List<CScheduleEntity> entities) {
		for (CScheduleEntity d : entities) {
			if (d.getSDatastate().equals("删除")) {
				cScheduleDao.delete(d.getGuid());
			} else {
				CScheduleEntity cScheduleEntity = cScheduleDao.queryObject(d.getGuid());
				if (cScheduleEntity == null) {
					cScheduleDao.save(d);
				} else {
					cScheduleDao.update(d);
				}
			}
		}
	}
	
}
